package zmh.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;
import zmh.lookup.FruitFactory;

/**
 * @author zhangminhang1
 */
@Service
public class SearchReceive implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    FruitFactory fruitFactory;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        //保证只执行一次
        if (contextRefreshedEvent.getApplicationContext().getParent() == null) {
            System.out.println(fruitFactory.getFruit().getName());
        }
    }
}